package com.tma.internship.activities;

import com.tma.internship.ClassesInfo.ControlBookMark;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class BookmarkDialog extends Dialog implements android.view.View.OnClickListener{
	private EditText text;
	private Button ok_btn;
	private Button cancel_btn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.book_mark);
		text = (EditText) findViewById(R.id.text_cmt);
		text.setText("");
		ok_btn = (Button) findViewById(R.id.ok_btn);
		cancel_btn = (Button) findViewById(R.id.cancel_btn);
		setCancelable(true);
		ok_btn.setOnClickListener(this);
		cancel_btn.setOnClickListener(this);
	}

	private String bookName;
	private int page;
	public BookmarkDialog(Context context,String bookName,int page) {
		super(context);
		// TODO Auto-generated constructor stub
		this.bookName = bookName;
		this.page = page;
		setTitle(context.getString(R.string.title_bookmar_dlg)+" "+bookName+" - "+context.getString(R.string.page)+" "+ page);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v == ok_btn){
           ControlBookMark ctr = new ControlBookMark(getContext());
           ctr.write(bookName, text.getText().toString(), page);
           Toast.makeText(getContext(), getContext().getString(R.string.book_mark_success), Toast.LENGTH_SHORT).show();
		}
		dismiss();
	}
}
